package org.elephas.webapp.frontend.page;

import org.apache.wicket.Component;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.elephas.webapp.frontend.component.Toolbar;

/**
 * This class is used to provide the basic structure of a page.
 * 
 * @author Gerolf Seitz
 * 
 */
public abstract class AbstractBasePage extends WebPage {
	private static final long serialVersionUID = 1L;

	/**
	 * Construct.
	 */
	public AbstractBasePage() {
		this(new PageParameters());
	}

	public AbstractBasePage(PageParameters params) {
		super(params);
		checkParameters(params);
		add(new Toolbar("toolbar"));
	}

	@Override
	protected void onBeforeRender() {
		super.onBeforeRender();
		if (get("header") == null) {
			add(newHeader("header"));
		}
		if (get("content") == null) {
			add(newContent("content"));
		}
		if (get("footer") == null) {
			add(newFooter("footer"));
		}
	}

	/**
	 * Can be used to run sanity checks for the page parameters.
	 * 
	 * @param params
	 *            the page parameters
	 */
	protected void checkParameters(PageParameters params) {
		// do nothing
	}

	/**
	 * Factory method for creating the header.
	 * 
	 * @param id
	 *            the id of the header
	 * @return the header
	 */
	protected abstract Component newHeader(String id);

	/**
	 * Factory method for creating the footer.
	 * 
	 * @param id
	 *            the id of the footer
	 * @return the footer
	 */
	protected abstract Component newFooter(String id);

	/**
	 * Factory method for creating the content container.
	 * 
	 * @param id
	 *            the id of the content container
	 * @return the content container
	 */
	protected abstract Component newContent(String id);

}
